home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DDJMAG / DDJ9203.ZIP / OOPASM.ZIP / MENU.ASM < prev    next >
Assembly Source File  |  1994-03-04  |  10KB  |  412 lines

  1.     .MODEL    SMALL
  2.  
  3.     INCLUDE    equates.inc
  4.     INCLUDE    instance.inc
  5.     INCLUDE    messages.inc
  6.     INCLUDE    objects.inc
  7.  
  8.     FlashDelay    EQU    0EFFFh        ;Empty loop count
  9.  
  10. IF1
  11.     INCLUDE    macros.mac
  12.     INCLUDE    objects.mac
  13.     INCLUDE    strings.mac
  14.     INCLUDE    video.mac
  15. ENDIF
  16.  
  17.     EXTRN    hideMouseCursor:NEAR
  18.     EXTRN    sendMsg:NEAR
  19.  
  20.     EXTRN    Self:WORD
  21.  
  22.     .CODE
  23.  
  24.     PUBLIC    menuInstVars
  25. COMMENT    %
  26. ==============================================================================
  27. Gets the instance variables for Menu objects.
  28.  
  29. Passes:    bl - Color
  30.     cx - Lower/Right row/column
  31.     di - Menu index ptr
  32.     dx - Upper/Left row/column
  33.     si - Menu table ptr
  34.  
  35. =============================================================================%
  36. menuInstVars    PROC    NEAR
  37.     getInst        dh,Row1,Self        ;Get upper row
  38.     getInst        dl,Col1            ;Get left column
  39.     getInst        ch,Row2            ;Get lower row
  40.     getInst        cl,Col2            ;Get right column
  41.     getInst        bl,Color        ;Get window color
  42.     getInst        di,InxPtr        ;Menu index pointer
  43.     getInst        si,MenuPtr        ;Menu pointer
  44.     ret
  45. menuInstVars    ENDP
  46.  
  47.  
  48.  
  49. IF Dbug
  50.     PUBLIC    hiliteOff
  51. ENDIF
  52. COMMENT    %
  53. ==============================================================================
  54. Turns off the currently hilited menu item.
  55.  
  56. =============================================================================%
  57. hiliteOff    PROC    NEAR
  58.     call        menuInstVars
  59.     add        si,di            ;Point to menu entry
  60.     call        disMenuItem        ;De-Hilite menu item
  61.     ret
  62. hiliteOff    ENDP
  63.  
  64.  
  65.  
  66. COMMENT    %
  67. ==============================================================================
  68. Hilites a menu item.
  69.  
  70. Passed:    StackTop - New menu index
  71.  
  72. =============================================================================%
  73. hiliteOn    PROC    NEAR
  74.     call        hideMouseCursor        ;Hide mouse cursor
  75.     call        menuInstVars
  76.     getStackArgs    di            ;Get menu index
  77.     reverseVideo    bl            ;Get reverse video attr
  78.     add        si,di            ;Point to menu entry
  79.     call        disMenuItem        ;Hilite menu item
  80.     setInst        InxPtr,di,Self        ;Set new menu index 
  81.     ret
  82. hiliteOn    ENDP
  83.  
  84.  
  85.  
  86. COMMENT    %
  87. ==============================================================================
  88. Displays a menu item.
  89.  
  90. Passed:    bl - Color
  91.     cx - Lower/Right row/column
  92.     dx - Upper/Left row/column
  93.     si - Menu item handle
  94.  
  95. =============================================================================%
  96. disMenuItem    PROC    NEAR
  97.     pushData    <cx,di>
  98.     mov        dx,Wptr[si]        ;Get row/col
  99.     mov        si,Wptr[si+2]        ;Get string address
  100.     push        dx
  101.     disStrg        dh,dl,bl,si        ;Display the string
  102.     pop        dx
  103.  
  104.     getInst        ch,Row2,Self        ;Get lower row
  105.     getInst        cl,Col2            ;Get right column
  106.     sub        ch,dh            ;Calc window height
  107.     zero        ch,dsmi1        ;Horizontal menu? - Exit
  108.     push        dx
  109.     disAttr        dh,dl,cl,bl        ;Else - Display the attributes
  110.     pop        dx
  111. dsmi1:    popData        <di,cx>
  112.     ret
  113. disMenuItem    ENDP
  114.  
  115.  
  116.  
  117. IF Dbug
  118.     PUBLIC    nextMenuItem
  119. ENDIF
  120. COMMENT    %
  121. ==============================================================================
  122. Moves the hilite to the next menu item.
  123.  
  124. =============================================================================%
  125. nextMenuItem    PROC    NEAR
  126.     call        menuInstVars_        ;Get menu data
  127.     dec        ch            ;Account for border
  128.  
  129.     add        di,4            ;Increment index ptr
  130.     add        si,di            ;Point to next menu item
  131.     identity    Wptr[si],nmi1        ;Next item ok? - Use it
  132.  
  133.     notZero        ax,nmi0            ;Vertical? - Jump
  134.     mov        ax,di
  135. nmi0:    sub        di,ax            ;Else use top item
  136.     jmp        nmi3
  137.  
  138. nmi1:    neq        Bptr[si-3],ch,nmi3    ;Not at bottom? - Skip
  139.     push        di
  140.     send        Self,ScrollUp,1        ;Else scroll
  141.     pop        di
  142.  
  143. nmi3:    send        Self,Hilite,di        ;Hilite menu item
  144.     ret
  145. nextMenuItem    ENDP
  146.  
  147.  
  148.  
  149. IF Dbug
  150.     PUBLIC    prevMenuItem
  151. ENDIF
  152. COMMENT    %
  153. ==============================================================================
  154. Moves the hilite to the previous menu item.
  155.  
  156. =============================================================================%
  157. prevMenuItem    PROC    NEAR
  158.     call        menuInstVars_        ;Get menu data
  159.     mov        ch,dh            ;Save upper row
  160.     inc        ch            ;Account for border
  161.  
  162.     notZero        di,pmi1            ;Not 1st item? - Use it
  163.     notZero        ax,pmi0            ;Vertical? - Jump
  164.  
  165. pmi4:    add        di,4            ;Increment index ptr
  166.     add        si,4            ;Point to next menu item
  167.     identity    Wptr[si],pmi4        ;Not end of tbl? - Loop
  168.     jmp        pmi5
  169.  
  170. pmi0:    add        di,ax            ;Else use bottom item
  171. pmi5:    sub        di,4            ;Point to last entry
  172.     jmp        pmi2
  173.  
  174. pmi1:    sub        di,4            ;Decrement index ptr
  175.     add        si,di
  176.     neq        Bptr[si+5],ch,pmi2    ;Not at top? - Skip
  177.     push        di
  178.     send        Self,ScrollDown,1    ;Else scroll
  179.     pop        di
  180.  
  181. pmi2:    send        Self,Hilite,di        ;Hilite new menu item
  182.     ret
  183. prevMenuItem    ENDP
  184.  
  185.  
  186.  
  187. COMMENT    %
  188. ==============================================================================
  189. Helper function that returns menu data for next/prevMenuItem procedures.
  190.  
  191. Passes:    ax - Number of menu items
  192.     bl - Color
  193.     cx - Lower/Right row/column
  194.     di - Menu index ptr
  195.     dx - Upper/Left row/column
  196.     si - Menu table ptr
  197.  
  198. =============================================================================%
  199. menuInstVars_    PROC    NEAR
  200.     call        menuInstVars
  201.     xor        ax,ax
  202.     eq        ch,dh,mni1        ;Horizontal? - Exit
  203.     push        cx
  204.     sub        ch,dh            ;Get window height
  205.     dec        ch            ;Number of visible menu items
  206.     mov        cl,ch            ;Set up loop counter
  207.     xor        ch,ch
  208.     mov        al,4            ;Calculate offset
  209.     mul        cl            ;Bottom-Top=ax
  210.     pop        cx
  211. mni1:    ret
  212. menuInstVars_    ENDP
  213.  
  214.  
  215.  
  216. IF
  217.     PUBLIC    selectItem
  218. ENDIF
  219. COMMENT    %
  220. ==============================================================================
  221. Selects the currently hilited menu item by calling the specified procedure.
  222.  
  223. =============================================================================%
  224. selectItem    PROC    NEAR
  225.     getInst        bx,InxPtr,Self        ;Current menu item
  226.     getInst        si,MenuTbl        ;Current menu tbl
  227.     null        bx,slm2            ;Exit if Nil
  228.  
  229.     sendLoop    si,bx,bx+2        ;Send messages
  230.  
  231. slm2:    ret
  232. selectItem    ENDP
  233.  
  234.  
  235.  
  236. COMMENT    %
  237. ==============================================================================
  238. Updates next visible menu item with row and column data.
  239.  
  240. =============================================================================%
  241. updateNextItem    PROC    NEAR
  242.     call        updateItem_        ;Get menu data
  243.     mov        Wptr[si+4],dx        ;Update next menu item
  244. uni1:    dec        dh            ;Decrement row
  245.     mov        Wptr[si],dx        ;Save new row
  246.     sub        si,4            ;Point to prev menu item
  247.     mov        dx,Wptr[si]        ;Get row/col
  248.     loop        uni1
  249.     ret
  250. updateNextItem    ENDP
  251.  
  252.  
  253.  
  254. COMMENT    %
  255. ==============================================================================
  256. Updates previous visible menu item with row and column data.
  257.  
  258. =============================================================================%
  259. updatePrevItem    PROC    NEAR
  260.     call        updateItem_        ;Get menu data
  261.     mov        Wptr[si-4],dx        ;Update prev menu item
  262. upi1:    inc        dh            ;Increment row
  263.     mov        Wptr[si],dx        ;Save new row
  264.     add        si,4            ;Point to next menu item
  265.     mov        dx,Wptr[si]        ;Get row/col
  266.     loop        upi1
  267.     ret
  268. updatePrevItem    ENDP
  269.  
  270.  
  271.  
  272. COMMENT    %
  273. ==============================================================================
  274. A helper function that returns common instance data for updating location
  275. information for scrollable menus.
  276.  
  277. =============================================================================%
  278. updateItem_    PROC    NEAR
  279.     call        menuInstVars
  280.  
  281.     sub        ch,dh            ;Get window height
  282.     dec        ch            ;Number of visible menu items
  283.     mov        cl,ch            ;Set up loop counter
  284.     xor        ch,ch
  285.  
  286.     add        si,di            ;Point to menu entry
  287.     mov        dx,Wptr[si]        ;Get row/col
  288.     ret
  289. updateItem_    ENDP
  290.  
  291.  
  292.  
  293. COMMENT    %
  294. ==============================================================================
  295. Hilites the 1st menu item.
  296.  
  297. =============================================================================%
  298. menuOn    PROC    NEAR
  299.     call        hideMouseCursor        ;Hide mouse cursor
  300.     call        menuInstVars
  301.     xor        di,di            ;Hilite zeroth menu item
  302.     reverseVideo    bl            ;Get reverse video attr
  303.     call        disMenuItem        ;Hilite menu item
  304.     setInst        InxPtr,di,Self        ;Set new menu index 
  305.     ret
  306. menuOn    ENDP
  307.  
  308.  
  309.  
  310. IF Dbug
  311.     PUBLIC    flashHilite
  312. ENDIF
  313. COMMENT    %
  314. ==============================================================================
  315. Flashes the hilite for the specified menu item.
  316.  
  317. Passed:    StackTop - New menu index pointer
  318.  
  319. =============================================================================%
  320. flashHilite    PROC    NEAR
  321.     call        hideMouseCursor        ;Hide mouse cursor
  322.     getStackArgs    di            ;Get new menu index
  323.     call        flashHilite_
  324.     call        flashHilite_
  325.     ret
  326. flashHilite    ENDP
  327.  
  328.  
  329.  
  330. COMMENT    %
  331. ==============================================================================
  332. Turns the hilite off pauses then turns it back on for the specified menu item.
  333.  
  334. Passed:    di - New menu index pointer
  335.  
  336. =============================================================================%
  337. flashHilite_    PROC    NEAR
  338.     push        di
  339.     push        di
  340.     call        hiliteOff        ;Turn off hilite
  341.     mov        cx,FlashDelay        ;Loop counter
  342. flh1:    loop        flh1            ;Delay
  343.     call        menuInstVars        ;Get instance values
  344.     pop        di
  345.     reverseVideo    bl            ;Get reverse video attr
  346.     add        si,di            ;Point to menu entry
  347.     call        disMenuItem        ;Hilite menu item
  348.     setInst        InxPtr,di,Self        ;Set menu index 
  349.     mov        cx,FlashDelay        ;Loop counter
  350. flh2:    loop        flh2            ;Delay
  351.     pop        di
  352.     ret
  353. flashHilite_    ENDP
  354.  
  355.  
  356.  
  357.     .DATA
  358.  
  359. defMsg    Menu,\
  360.     Read,\
  361.     <menuOn,,>
  362.  
  363. defMsg    Menu,\
  364.     Next,\
  365.     <nextMenuItem,,>
  366.  
  367. defMsg    Menu,\
  368.     Prev,\
  369.     <prevMenuItem,,>
  370.  
  371. defMsg    Menu,\
  372.     Select,\
  373.     <,,selectItem>
  374.  
  375. defMsg    Menu,\
  376.     ScrollUp,\
  377.     <,,updateNextItem>
  378.  
  379. defMsg    Menu,\
  380.     ScrollDown,\
  381.     <,,updatePrevItem>
  382.  
  383. defMsg    Menu,\
  384.     Hilite,\
  385.     <hiliteOff,,hiliteOn>
  386.  
  387. defMsg    Menu,\
  388.     DeHilite,\
  389.     <hiliteOff,,>
  390.  
  391. defMsg    Menu,\
  392.     Flash,\
  393.     <flashHilite,,>
  394.  
  395. defMsg    Menu,\
  396.     SelectNext,\
  397.     <nextMenuItem,,selectItem>
  398.  
  399. defMsg    Menu,\
  400.     SelectPrev,\
  401.     <prevMenuItem,,selectItem>
  402.  
  403. defObj    Menu,\
  404.     <>,\
  405.     <>\
  406.     <Read,Next,Prev,Select,ScrollUp,ScrollDown,Hilite,DeHilite,Flash,\
  407.     SelectNext,SelectPrev>
  408.  
  409.  
  410.  
  411.     END
  412.